﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Medianamik.Core.Interfaces;
using Medianamik.Core.Security;

namespace Medianamik.Core.DAL.SubSonicDAL
{
    public partial class Group : IGroupFull
    {
        public string GroupName
        {
            get { return Name; }
        }

        public bool Equals(IGroupFull other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.ID.Equals(ID);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(IGroupFull)) return false;
            return Equals((IGroupFull)obj);
        }

        public override int GetHashCode()
        {
            return ID.GetHashCode();
        }

        public Guid ID
        {
            get { return GroupId; }
        }

        public Guid? ParentID
        {
            get { return ParentGroupId; }
        }

        public int ChildrenCount
        {
            get { return SecurityManager.GetChildGroupsCount(GroupId); }
        }

        public IEnumerable<IGroupFull> GetAllChildGroups()
        {
            return SecurityManager.GetChildGroups(GroupId, 0);
        }

        public IGroupFull Parent
        {
            get { return SecurityManager.GetGroup(ParentGroupId); }
        }

        public IEnumerable<IGroupFull> GetChildGroups(int depth)
        {
            return SecurityManager.GetChildGroups(GroupId, depth);
        }
    }
}
